// pages/myplan/myplan.js
const app = getApp()
Page({
  data: {
    list:[],
    height:800,
  },
  onLoad: function (options) {
    //hgz/demand/queryListWithPage
    var windowHeight = app.globalData.windowHeight;
    this.setData({
      height: windowHeight
    })
    var params = {
      pageNum:1,
      pageSize:1000
    }
    app.request.postHeadForm('hgz/demand/querySelfListWithPage', params)
    .then(res =>{
        var dataList = res.data.list;
        for(var i=0;i<dataList.length;i++){
          var masterialList = dataList[i].material.split(',');
          var modelList = dataList[i].model.split(',');
          var weightList = dataList[i].weight.split(',');
          var childList = [];
          for(var j=0;j<masterialList.length;j++){
            var maters = masterialList[j];
            var  models = "";
            var  weighs = "";
            if(j<modelList.length){
              models = modelList[j];
            }  
            if(j<weightList.length){
              weighs = weightList[j];
            }  
            childList.push({
              mater:maters,
              model:models,
              weigh:weighs
            })
          }
          dataList[i].childList = childList;


          var imgList2 = dataList[i].imgPath.split(';');
          var imgList = [];
          for(var j=0;j<imgList2.length;j++){
            if(imgList2[j]!=null&&imgList2[j].length>5){
              imgList.push(imgList2[j])  
            }
          }
          dataList[i].banner = imgList;
        }
        this.setData({
          list:dataList
        })
    })
  },
  detail(e){
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/demanddetail/demand?id=' + id,
    })
  },
  showImageBanner(e){
    var itemIndex = e.currentTarget.dataset.id;
    var banner = e.currentTarget.dataset.val;
    wx.previewImage({
      current: banner[itemIndex], // 当前显示图片的http链接
      urls: banner // 需要预览的图片http链接列表
    })
  }

})